package com.venn.service.imp;

import com.venn.dao.NaviPageMapper;
import com.venn.entity.NaviPage;
import com.venn.service.NaviPageService;
import com.venn.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Venn on 2017/8/27.
 */
@Service("naviPageService")
public class NaviPageServiceImp implements NaviPageService {

    @Autowired
    NaviPageMapper naviPageMapper;

    /**
     * find all:
     *      six item a line, so every six item put to a map from col1 to col5
     * @param userId
     * @return
     */
    @Override
    public List<HashMap<String,NaviPage>> findAll(String userId) {
        // get all navipage item
        List<NaviPage> naviPages = naviPageMapper.findAll(userId);
        // size
//        int size = naviPages.size();
        List<HashMap<String,NaviPage>> list = new ArrayList<>();
        HashMap<String,NaviPage> map = null;
        // 遍历结果集，每六条放到一个map中，构造一行六个导航链接
        for (int i=0; i< naviPages.size(); i++){
            // Constants.LEN is 5
            if(i% Constants.LEN == 0){
                map = new HashMap<>();
                list.add(map);
            }
            map.put("col"+i%Constants.LEN,naviPages.get(i));


        }

        return list;
    }

    @Override
    public int add(NaviPage naviPage) {
        return naviPageMapper.add(naviPage);
    }

    @Override
    public boolean finishSelect(String[] ids) {
        return false;
    }

    @Override
    public boolean modify(NaviPage naviPage) {
        return false;
    }

    @Override
    public boolean remove(String deleteflag) {
        return false;
    }
}
